/**
 * Returns result or null if problem occures or result not found
 *
 * @param item
 */
function getItemFromLocalstorage(item) {
    try {
        if (isCurrentLocalStorageVersion()) {
            return localStorage.getItem(item);
        }
        else {
            clearAllLocalStorageValues();
        }
    } catch(e) {
        log('There was a problem retrieving result for "' + item + '"');
        return null;
    }
}

function setItemToLocalStorage(key, value) {
    if (!isCurrentLocalStorageVersion()) {
        clearAllLocalStorageValues();
    }
    try {
        localStorage.setItem(key, value);
    } catch(e) {
        log('There was a problem setting ' + key + ' value to ' + value);
    }
}

function isCurrentLocalStorageVersion() {
    result = null;
    try {
        result = localStorage.getItem('localStorageVersion');
    } catch(e) {
        log('LocalStorage version check error occurred');
    }
    if (result === null) {
        return true;
    }
    else if (result == OurGame.localStorageVersion) {
        return true;
    }
    return false;
}

function clearAllLocalStorageValues() {
    localStorage.clear();
}